import java.time.*;
import java.time.format.DateTimeFormatter;

public class NewDate {

    //获取当前时间戳
    public Long getCurrTimeStamp(){
        Instant instant=Instant.now();
        return instant.getEpochSecond();//从1970-01-01T00：00：00Z的Java时代获取秒数
    }

    //获取当前日期时间
    public String getNowDate(){
        LocalDate localDate=LocalDate.now();
        return localDate.toString();
    }

    //获取当前年/月/日/时/分/秒
    public String getDateString(){
        LocalDate localDate=LocalDate.now();
        return localDate.getYear()+"-"+localDate.getMonthValue()+"-"+localDate.getDayOfMonth();
    }

    //自定义日期转时间戳
    public Long strtotime(String date,String format){
        DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern(format);
        LocalDateTime localDateTime=LocalDateTime.parse(date,dateTimeFormatter);
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
    }
    //时间戳转日期时间
    public String toDate(String format,Long timeStamp){
        DateTimeFormatter dtf=DateTimeFormatter.ofPattern(format);
        return dtf.format(LocalDateTime.ofInstant(Instant.ofEpochSecond(timeStamp),ZoneId.systemDefault()));
    }

    //日期间隔
}
